import {
	getUserInfo
} from '../api/user.js'

import flyrise from "../tools/flyrise.js"
import * as sp from '../common/sp_config.js'

/**
 * 初始化时，缓存用户信息
 */
export const initCacheUserInfo = (callback) => {
	getUserInfo().then((res) => {
		let reslut = res.data
		if (reslut.code == 200) {
			loginSuccess(reslut.data)
			callback(true, reslut.data)
		} else {
			callback(false)
		}
	}).catch((err) => {
		callback(false)
	})
}

const loginSuccess = (data) => {
	flyrise.save(sp.parkId, data.parkId)
	flyrise.save(sp.parkName, data.parkName)
	flyrise.save(sp.userName, data.username)
	flyrise.save(sp.entId, data.entId)
	flyrise.save(sp.entName, data.entName)
	flyrise.save(sp.staffId, data.staffId)
	flyrise.save(sp.userId, data.userId)
	flyrise.save(sp.phone, data.phoneNumber)
}
